#include "DashboardUI.h"
#include "ui_dashboard.h"

#include "Authentication.h"

#include "DashboardUI_AddRecord.h"
#include "DashboardUI_ViewRecords.h"
#include "DashboardUI_EditUser.h"

#include "UIManager.h"

#include <stdio.h>

Dashboard::Dashboard(UIManager *manager, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Dashboard)
{
    ui->setupUi(this);
    this->manager = manager;

    User *user = Authentication::getInstance()->getUser();

    // Set up tabs based on user type
    switch (user->getUserType())
    {
        case User::ADMIN:
            addTab(new DashboardUI_EditUser(), "Create User");
            setWindowTitle("Admin Dashboard");
            break;

        case User::DOCTOR:
            addTab(new DashboardUI_AddRecord(), "Add Record");
            addTab(new DashboardUI_ViewRecords(), "View All Records");
            setWindowTitle("Doctor Dashboard");
            break;

        case User::PATIENT:
            addTab(new DashboardUI_AddRecord(), "Add Record");
            addTab(new DashboardUI_ViewRecords(), "View All Records");
            addTab(new DashboardUI_EditUser(), "View Information");
            setWindowTitle("Patient Dashboard");
            break;

        case User::NURSE:
            addTab(new DashboardUI_AddRecord(), "Add Record");
            addTab(new DashboardUI_ViewRecords(), "View All Records");
            addTab(new DashboardUI_EditUser(), "Create User");
            setWindowTitle("Nurse Dashboard");
            break;

        default:
            addTab(new DashboardUI_AddRecord(), "Add Record");
            addTab(new DashboardUI_ViewRecords(), "View All Records");
    }

    show();
}

void Dashboard::addTab(QWidget *tab, QString tabTitle)
{
    //tabList.push_back(tab);
    ui->tabWidget->addTab(tab, tabTitle);
}

Dashboard::~Dashboard()
{
    delete ui;
}

void Dashboard::on_actionLogout_triggered()
{
    hide();
    manager->showLogin();
}
